package nc.vo.arap.global;

import java.util.Vector;
import nc.itf.fi.pub.Account;
import nc.vo.arap.exception.ExceptionHandler;
import nc.vo.bd.b120.AccidVO;
import nc.vo.ep.dj.DJZBHeaderVO;
import nc.vo.ep.dj.DJZBItemVO;
import nc.vo.ep.dj.DJZBVO;
import nc.vo.ml.AbstractNCLangRes;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDouble;

public class DjVoTreaterYs_bak extends DjVOTreater
{
  public DjVoTreaterYs_bak(DJZBVO djzbvo)
  {
    this.aid = new DjVOTreaterAid(djzbvo);
  }

  protected void doBefSaveCheckHvo(DJZBHeaderVO headvo, DjCheckParamVO paramvo) throws BusinessException {
    if (this.aid.getIsQc()) {
      ResMessage res = checkQcdj_jzxx();
      if (!(res.isSuccess)) {
        ExceptionHandler.debug(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000375"));
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000375") + res.strMessage);
      }
    }
  }

  protected void doBefSaveCheckBvo(DJZBVO djzbvo, DjCheckParamVO paramVO)
    throws BusinessException
  {
    DJZBItemVO[] items = (DJZBItemVO[])(DJZBItemVO[])djzbvo.getChildrenVO();
    for (DJZBItemVO item : items) {
      if (!(item.getJfbbje().add(item.getDfbbje()).equals(item.getBbye())))
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("200602", "UPP200602-v50-000173"));
      if (!(item.getJfybje().add(item.getDfybje()).equals(item.getYbye())))
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("200602", "UPP200602-v50-000174"));
      if (!(item.getJffbje().add(item.getDffbje()).equals(item.getFbye())))
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("200602", "UPP200602-v50-000175"));
    }
    String strDjdl = ((DJZBHeaderVO)djzbvo.getParentVO()).getDjdl();
    if (("ys".equals(strDjdl)) || ("yf".equals(strDjdl)))
      doBefSaveCheckBvoYsYf(djzbvo);
    else if (("sk".equals(strDjdl)) || ("fk".equals(strDjdl)))
      doBefSaveCheckBvoSkFk(djzbvo, paramVO);
  }

  protected void doBefSaveCheckBvoYsYf(DJZBVO djzbvo)
    throws BusinessException
  {
    DJZBItemVO[] itemsvo = null;

    itemsvo = (DJZBItemVO[])(DJZBItemVO[])djzbvo.getChildrenVO();

    for (int i = 0; i < itemsvo.length; ++i)
    {
      String strLang;
      if (itemsvo[i].getStatus() == 3) {
        continue;
      }

      if (itemsvo[i].getSl() != null)
      {
        if (ArapCommonTool.isLessZero(itemsvo[i].getSl()))
        {
          strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
          throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000698"));
        }

      }

      if (itemsvo[i].getDj() != null)
      {
        if (ArapCommonTool.isLessZero(itemsvo[i].getDj())) {
          strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
          throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000699"));
        }

      }

      if ((itemsvo[i].getWldx() == null) || (itemsvo[i].getWldx().intValue() == -1)) {
        throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000629") + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000700"));
      }
      if (itemsvo[i].getWldx().equals(new Integer(0))) {
        ExceptionHandler.debug(NCLangRes4VoTransl.getNCLangRes().getStrByID("common", "UC000-0001589"));
        if ((itemsvo[i].getKsbm_cl() != null) && (itemsvo[i].getKsbm_cl().toString().trim().length() >= 1))
          continue;
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000726"));
      }

      if (itemsvo[i].getWldx().equals(new Integer(1))) {
        ExceptionHandler.debug(NCLangRes4VoTransl.getNCLangRes().getStrByID("common", "UC000-0000275"));
        if ((itemsvo[i].getKsbm_cl() != null) && (itemsvo[i].getKsbm_cl().toString().trim().length() >= 1))
          continue;
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000727"));
      }

      if (itemsvo[i].getWldx().equals(new Integer(2))) {
        ExceptionHandler.debug(NCLangRes4VoTransl.getNCLangRes().getStrByID("common", "UC000-0004064"));
        if ((itemsvo[i].getDeptid() != null) && (itemsvo[i].getDeptid().toString().trim().length() >= 1))
          continue;
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000728"));
      }

      if (itemsvo[i].getWldx().equals(new Integer(3))) {
        ExceptionHandler.debug(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPT2006030102-000013"));
        if ((itemsvo[i].getYwybm() != null) && (itemsvo[i].getYwybm().toString().trim().length() >= 1))
          continue;
        throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000729"));
      }
    }
  }

  protected void doBefSaveCheckBvoSkFk(DJZBVO djzbvo, DjCheckParamVO paramVO)
    throws BusinessException
  {
    DJZBItemVO[] itemsvo = null;

    DJZBHeaderVO headvo = new DJZBHeaderVO();

    headvo = (DJZBHeaderVO)djzbvo.getParentVO();
    itemsvo = (DJZBItemVO[])(DJZBItemVO[])djzbvo.getChildrenVO();

    Vector ddh = new Vector();
    for (int i = 0; i < itemsvo.length; ++i)
    {
      String strLang;
      if (itemsvo[i].getStatus() == 3) {
        continue;
      }

      if (itemsvo[i].getSl() != null)
      {
        if (ArapCommonTool.isLessZero(itemsvo[i].getSl())) {
          strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
          throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000698"));
        }

      }

      if (itemsvo[i].getDj() != null)
      {
        if (ArapCommonTool.isLessZero(itemsvo[i].getDj()))
        {
          strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
          throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000699"));
        }

      }

      if ((itemsvo[i].getWldx() == null) || (itemsvo[i].getWldx().intValue() == -1))
      {
        strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
        throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000700"));
      }

      if ((itemsvo[i].getWldx().equals(new Integer(0))) || (itemsvo[i].getWldx().equals(new Integer(1))))
      {
//        if ((itemsvo[i].getKsbm_cl() != null) && (itemsvo[i].getKsbm_cl().trim().length() >= 1)) {
//          break label659;
//        }
        strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
        throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000714"));
      }
      if (itemsvo[i].getWldx().equals(new Integer(2)))
      {
//        if ((itemsvo[i].getDeptid() != null) && (itemsvo[i].getDeptid().trim().length() >= 1)) {
//          break label659;
//        }
        strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
        throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000702"));
      }
      if ((itemsvo[i].getWldx().equals(new Integer(3))) && ((
        (itemsvo[i].getYwybm() == null) || (itemsvo[i].getYwybm().trim().length() < 1))))
      {
        strLang = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000697", null, new String[] { String.valueOf(i + 1) });
        throw ExceptionHandler.createException(strLang + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000703"));
      }

      if (itemsvo[i].getBzbm() == null) {
        label659: throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000695"));
      }

      if (itemsvo[i].getAccountid() != null) if (itemsvo[i].getAccountid().trim().length() >= 1)
        {
          if (null == itemsvo[i].getZhbzbm()) {
            AccidVO accidvo = Account.queryAccountDocByPk(itemsvo[i].getAccountid());
            if (null != accidvo)
              itemsvo[i].setZhbzbm(accidvo.getPk_currtype());
          }
          if (!(itemsvo[i].getBzbm().equals(itemsvo[i].getZhbzbm()))) {
            throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000375") + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000696"));
          }

        }


      if ("fk".equals(headvo.getDjdl())) {
        if ((itemsvo[i].getDdh() != null) && (itemsvo[i].getDdh().trim().length() > 0))
        {
          ddh.addElement(itemsvo[i].getDdh());
        }
        if ((this.aid.getPOIsUsed(paramVO) == null) || (!(this.aid.getPOIsUsed(paramVO).booleanValue())) || (ddh.size() <= 0))
          continue;
        try
        {
          String[] contra = new String[ddh.size()];
          ddh.copyInto(contra);
        }
        catch (Exception e2) {
          throw ExceptionHandler.createException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000375") + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006030102", "UPP2006030102-000705"), e2);
        }
      }
    }
  }
}